﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Collections;
using MulagoDb.model_old;

namespace MulagoDb.database
{
    public class ProblemList
    {
        public static void insetProblemList(int pid, string single_select, string documented_sepsis, 
            string abnormal_tcd, string stroke, string retinopathy, string avascular_necrosis, 
            string leg_ulcer, string pregnancy, string rbc_alloimmunisation) {

                MySqlConnection connection = new MySqlConnection(PatientRegistration.myConString);
                connection.Open();
                MySqlCommand command = connection.CreateCommand();
                string query = "INSERT INTO problemlist VALUES(" + pid + ",now(),'" +
                    single_select + "','" + documented_sepsis + "','" +
                    abnormal_tcd + "','" + stroke + "','" + retinopathy + "','" +
                    avascular_necrosis + "','" + leg_ulcer + "','" + pregnancy + "','" +
                   rbc_alloimmunisation+ "')";
                command.CommandText = query;
                MySqlDataReader reader = command.ExecuteReader();
                connection.Close();
        }
        public static ArrayList getProblemList(int patientId) {
            ArrayList result = new ArrayList();
            MySqlConnection connection = new MySqlConnection(PatientRegistration.myConString);
            connection.Open();
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT * FROM problemlist WHERE pid = " + patientId;
            MySqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                Problems problem = new Problems();
                problem.setPid(reader.GetInt32(0));
                problem.setDate(reader.GetValue(1).ToString());
                problem.setSingleSelect(reader.GetValue(2).ToString());
                problem.setDocumentSepsis(reader.GetValue(3).ToString());
                problem.setAbnormaltcd(reader.GetValue(4).ToString());
                problem.setStroke(reader.GetValue(5).ToString());
                problem.setRetinopathy(reader.GetValue(6).ToString());
                problem.setAvascularneclosis(reader.GetValue(7).ToString());
                problem.setLegulcer(reader.GetValue(8).ToString());
                problem.setPregnancy(reader.GetValue(9).ToString());
                problem.setRbcalloimmunisation(reader.GetValue(10).ToString());
                result.Add(problem);
            }
            return result;
        }
    }
}
